package com.artPreter.config;


import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

public class RedirectFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;

        // 检查请求的URL是否匹配
        if (httpRequest.getRequestURL().toString().contains("http://47.119.139.202:18064")) {
            String url = httpRequest.getRequestURL().toString().replaceAll("http://47.119.139.202:18064","https://surnwo.com");
            // 重定向到目标URL
            httpResponse.sendRedirect(url);
            return;
        }

        // 继续处理其他请求
        chain.doFilter(request, response);
    }
}
